﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Net;
using System.Text;
using System.IO;

public partial class xmlPost : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Bt_Submit_Click(object sender, EventArgs e)
    {
        string data = TB_postSample.Text;

        HttpWebRequest dataRequest = (HttpWebRequest)HttpWebRequest.Create(Request.Url.AbsoluteUri.Replace("xmlPost.aspx", "Submit.aspx"));

        ASCIIEncoding encoding = new ASCIIEncoding();
        byte[] byteArray = encoding.GetBytes(data);

        dataRequest.Method = "POST";
        dataRequest.ContentType = "text/xml";
        dataRequest.ContentLength = byteArray.Length;

        try
        {
            Stream inputStream = dataRequest.GetRequestStream();
            inputStream.Write(byteArray, 0, byteArray.Length);
            inputStream.Close();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }

        try
        {
            WebResponse dataRespond = dataRequest.GetResponse();
            StreamReader rs = new StreamReader(dataRespond.GetResponseStream());

            string dataResult = rs.ReadToEnd();
            TB_postSample.Text = @"Result:" + dataResult;

            dataRespond.Close();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
}